package Ep06_BinaryTree.BT6_0226;

import Ep06_BinaryTree.TreeNode;

public class Mine {
    public TreeNode invertTree(TreeNode root) {
        if (root == null) return null;
        reverse(root);
        return root;
    }

    // 翻转方法
    public void reverse(TreeNode root) {
        if (root == null) return;
        if (root.left == null && root.right == null){
            return;
        } else {
            TreeNode temp = root.left;
            root.left = root.right;
            root.right = temp;
        }
        reverse(root.left);
        reverse(root.right);
    }
}
